import config
from utils import *


def register():
	return Help()


class Help:
	def __init__(self):
		self.type = 'passive'
		self.help = \
'''显示帮助：
	用法：
	*帮助
	*帮助 (查询词)	
	显示本段帮助。'''

	def run(self, gum, msg):
		if not msg['type'] in ['FriendMessage', 'GroupMessage'] \
				or len(msg['messageChain']) <= 1 \
				or msg['messageChain'][1]['type'] != 'Plain' \
				or msg['messageChain'][1]['text'].split()[0] != '*帮助':
			return

		text = msg['messageChain'][1]['text']
		splitted = text.split()

		chain = MsgChain()
		for bub in gum.bubbles:
			if hasattr(bub, 'help') and (len(splitted) <= 1 or splitted[1] in bub.help):
				chain.addPlain(bub.help + '\n\n')

		autoReply(chain, gum)